﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using SQLEditor.dal;

namespace SQLEditor.admin.service
{
    public class BaseService
    {
        private ThinggoEduDbEntities  _db = null;
        private string _connStr = "";
        public ThinggoEduDbEntities DB
        {
            get
            {
                if (_db == null)
                {
                    _db = new ThinggoEduDbEntities();
                }
                return _db;
            }
        }

        public string connStr { 
            get {
                return _connStr;
            } 
        }

        public BaseService()
        {
            if (_db == null)
            {
                _db = new ThinggoEduDbEntities();               
            }
            _connStr = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
        }
        

        public SqlParameter[] GetPagerParameters(string tablName, string columns, string order, string where, int pageSize, int pageIndex, SqlParameter paramTotalCount)
        {
            SqlParameter paramTableName = new SqlParameter("@tableName", tablName);
            SqlParameter paramColumns = new SqlParameter("@columns", "*");
            SqlParameter paramOrder = new SqlParameter("@order", order);
            SqlParameter paramPageSize = new SqlParameter("@pageSize", pageSize);
            SqlParameter paramPageIndex = new SqlParameter("@pageIndex", pageIndex);
            SqlParameter paramWhere = new SqlParameter("@where", where);
            SqlParameter[] paras = new SqlParameter[] { paramTableName, paramColumns, paramOrder, paramPageSize, paramPageIndex, paramWhere, paramTotalCount };
            return paras;
        }
    }
}